package com.szholly.pro.watergas_server.ps.data;

import java.util.HashMap;

import com.szholly.data.general.*;
import com.szholly.data.general.metadata.table.DefulatDomainTable;
import com.szholly.plug.safe.entity.user.UserEntity;
import org.springframework.stereotype.Component;
import com.szholly.data.general.metadata.IBaseTable;
import com.szholly.utils.spring.SpringBeanFactory;
import org.springframework.stereotype.Component;

/**
 * PollRoleUser
 */
@Component("PollRoleUser")
public class PollRoleUserTable extends InterceptorTableBase  implements IBaseTable{

	public final static String TABLE_NAME = "BC_POLL_ROLE";
	
	/**
	 * single ref
	 */
	public static PollRoleUserTable getSingleRef() {
		return (PollRoleUserTable) SpringBeanFactory.getBean("PollRoleUser");
	}

	@Override
	public String getMetadataTableName() {
		return TABLE_NAME;
	}

	@Override
	public String getMetadataTableAliasName() {
		return "PollRoleUser";
	}

	private HashMap<String, Field> fields;

	@Override
	protected HashMap<String, Field> fields() {
		if (fields == null) {
			fields = new HashMap<String, Field>();

			Field itemField = null;
			
			itemField = new Field();
			itemField.setFieldName(PollRoleUserRow.FIELD_Mn);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(5);
			itemField.setFieldAliasName("站点MN");
			itemField.setAllowNull(true);
			itemField.setMaxLen(200);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(PollRoleUserRow.FIELD_AlarmThreholdGuid);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(6);
			itemField.setFieldAliasName("该字段对应污染物报警阈值限表中的GUID，报警表和角色用户表一对多的关系");
			itemField.setAllowNull(true);
			itemField.setMaxLen(200);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(PollRoleUserRow.FIELD_Guid);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(7);
			itemField.setFieldAliasName("GUID");
			itemField.setAllowNull(false);
			itemField.setMaxLen(200);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(PollRoleUserRow.FIELD_PolluteCode);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(8);
			itemField.setFieldAliasName("站点污染物编号");
			itemField.setAllowNull(true);
			itemField.setMaxLen(200);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(PollRoleUserRow.FIELD_UserId);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(9);
			itemField.setFieldAliasName("用户ID");
			itemField.setAllowNull(true);
			itemField.setMaxLen(200);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
			itemField = new Field();
			itemField.setFieldName(PollRoleUserRow.FIELD_RoleCode);
			itemField.setDataType(GlobalDataType.String);
			itemField.setFieldID(10);
			itemField.setFieldAliasName("角色编号");
			itemField.setAllowNull(true);
			itemField.setMaxLen(200);
			fields.put(itemField.getFieldName().toUpperCase().trim(), itemField);
			
		}
		return fields;
	}
	private RelationNode relationNode;
	/**
	 * 表关系
	 */
	@Override
	public RelationNode getRelation() {
		if (relationNode == null) {
			relationNode = new RelationNode(TABLE_NAME);

			RelationInfo relationInfo = new RelationInfo();
			relationInfo.Foreignkey = new HashMap<String, String>();
			relationInfo.Foreignkey.put(PollRoleUserRow.FIELD_Guid, UserEntity.FIELD_USERID);
			relationInfo.RelationStrength = RelationStrength.UpdateChild;
			relationInfo.RelationType = RelationType.OneToMore;
			relationInfo.metadataTableAliasName = "阈值和用户关联关系";
			relationNode.getChildRelationNode().put("SAFE_USER", relationInfo);
		}
		return relationNode;
	}
	@Override
	public String getTableGroup() {
		return "PollRoleUser";
	}
}